BEGIN { 
		LeadingWhite = "^[ \t]+"
		Down  = "[a-z]"
		Up    = "[A-Z]"
		Word  = "A-Za-z0-9_"
		Class = Up   "[" Word "]*"
		Name  = Down "[" Word "]*"
        Pair = "(" Class "):(" Name ")" 
		Var   = "(" Name "_)[^" Word "]" 
}

$0 !~ LeadingWhite  && $1 ~ /Class/ && $3 == "=" 
      {Defined[$2] = $4}

$0 ~ LeadingWhite && Var  { var2fields() }
$0 ~ LeadingWhite && Pair { pair2fields() }
                          { print $0 }

function var2fields(     pair,name) {
	while(match($0,Var,pair))  {
		name=pair[1]
		if (! (name in Vars))
			print "!!! " name " : not known"
		sub(name, Vars[name])
	}
}
function pair2fields(   pair,class,var,renames) {
	while(match($0,Pair,pair))  {
		class = pair[1]
		var   = pair[2]	
	 	if (! (class in Defined ) )
			print "!!! " class " : not known"
		renames = Vars[var "_"] = rename(var,Defined[class])
		sub(class ":" var,renames,$0)
	}
}
function rename(pre,str,  tmp,n,out,i) {
	n=split(str,tmp,",")
	out = pre "_" tmp[1] 
	for(i=2;i<=n;i++)
		out=out "," pre "_" tmp[i] 
	return out
}	
